﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Word_Mojo
{
    /// <summary>
    /// The class, Tile, represents a playable letter to be used on the game board.  The tile has an 
    /// associated letter (char) value as well as a numeric point value.  Tile extends the PictureBox 
    /// control to show a visual representation of a specific letter
    /// </summary>
    class Tile : PictureBox
    {
        #region Properties

        public int PointValue { private set; get; }
        public string Letter { private set; get; }
        public bool IsLetter { private set; get; }
        public bool IsOnBoard { private set; get; }

        public Point Position { private set; get; }

        #endregion

        #region Construction

        /// <summary>
        /// Constructor for initializing a "blank tile" that gets displayed on the game board upon 
        /// first initializes the board.  The empty tiles have no point value and/or letter associated 
        /// with them.  Although, they do have a specific Point coordinate for its position on the board.
        /// </summary>
        /// <param name="column">The current column this Tile is located at on the board</param>
        /// <param name="row">The current row this Tile is located at on the board</param>
        public Tile(int column, int row)
        {
            this.PointValue = 0;
            this.Letter = String.Empty;
            this.IsLetter = false;
            this.IsOnBoard = true;
            this.Position = new Point(column, row);

            this.Image = Image.FromFile(@"..\..\Resources\blankTile.png");
            setupImageProperties();
        }

        /// <summary>
        /// Constructor for initializing a "player tile" that gets used directly by the player for spelling 
        /// words on the board.  This tile has a letter/point value, but no Position coordinate as it's not 
        /// being used on the board (yet).  
        /// </summary>
        /// <param name="value">The point value associated with this letter</param>
        /// <param name="letter">The letter of the Tile being created (single char)</param>
        public Tile(int value, string letter)
        {
            this.IsOnBoard = false;
            this.Position = new Point();

            initializeValue(value, letter);
            setupImageProperties();
        }

        /// <summary>
        /// Constructor for initializing a "board tile" to be displayed on the game board.  This tile has 
        /// a letter/point value as well as a specific Point coordinate for its position on the game board.
        /// </summary>
        /// <param name="value">The point value associated with this letter</param>
        /// <param name="letter">The letter of the Tile being created (single char)</param>
        /// <param name="column">The current column this Tile is located at on the board</param>
        /// <param name="row">The current row this Tile is located at on the board</param>
        public Tile(int value, string letter, int column, int row)
        {
            this.IsOnBoard = true;
            this.Position = new Point(column, row);

            initializeValue(value, letter);
            setupImageProperties();
        }

        #endregion

        #region Private Helper Methods

        /// <summary>
        /// Initializes values for a "Player Tile" or a "Board Tile".  Both types of Tile objects 
        /// get assigned a letter value, and as a result, a cooresponding point value and image.
        /// </summary>
        /// <param name="value">The point value associated with this letter</param>
        /// <param name="letter">The letter of the Tile being created (single char)</param>
        private void initializeValue(int value, string letter)
        {
            this.PointValue = value;
            this.Letter = letter;
            this.IsLetter = true;

            this.Image = Image.FromFile(@"..\..\Resources\" + letter + ".png");
        }

        /// <summary>
        /// Assigns various PictureBox properties for displaying the images correctly on the Form.  
        /// The SizeMode allows the blank/letter images to "fill" the contents of the control, and the 
        /// margin is adjusted to display the PictureBox properly on the TableLayoutPanel.
        /// </summary>
        private void setupImageProperties()
        {
            this.SizeMode = PictureBoxSizeMode.StretchImage;
            this.Dock = DockStyle.Fill;
            this.Margin = new Padding(0);
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// If this tile is placed on a "multiplier" cell on the game board, the point value for this 
        /// letter gets multiplied by some amount.  (Probably going to be a 2 or a 3 for Double/Triple 
        /// score multiplier).  
        /// </summary>
        /// <param name="multiplier">The amount to multiply this Tile's point value by</param>
        public void MultiplyPointValue(int multiplier)
        {
            this.PointValue *= multiplier;
        }

        #endregion
    }
}

